<#import "/WEB-INF/sys/js_css.html" as js>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>站点管理</title>
</head>
<body>
<table id="datagrid" class="easyui-datagrid" data-options="singleSelect:true,fit:true,fitColumns:true,pagination:true,
	url:'${ctx}/sys/site/search',toolbar:'#tools',rownumbers : true,pageSize:15,pageList:[5,10,15,20]">
    <thead>
		<tr>
			<th data-options="field:'id',hidden:true">id</th><!-- hidden -->
			<th data-options="field:'managerid',hidden:true">managerid</th><!-- hidden -->
			<th data-options="field:'createUser',hidden:true">createUser</th><!-- hidden -->
			<th data-options="field:'action',align:'center',width:2,formatter:formatterAction">操作</th>
			<th data-options="field:'sitename',width:15,align:'center'">站点名称</th>
			<th data-options="field:'sitetag',align:'center',width:33">百度搜索关键字</th>
			<th data-options="field:'domainname',align:'center',width:20">域名</th>
			<th data-options="field:'managername',align:'center',width:10">管理员</th>
			<th data-options="field:'createname',align:'center',width:10">创建人</th>
			<th data-options="field:'createTime',align:'center',width:10">创建人时间</th>
		</tr>
	</thead>
</table>
<!-- 站点配置div -->
<div id="divupdate" class="easyui-window" title="站点配置" data-options="modal:true,collapsible:false,closed:true,minimizable:false,
	maximizable:false,width:670,onClose:divupdateclose">
	<form id="toupdateform" method="post">
		<input type="hidden" name="id" id="updateid" value="" />
		<table class="table table-hover table-condensed">
			<tr>
				<td colspan="2">百度搜索关键字：&nbsp;&nbsp;&nbsp;&nbsp;<input id="updatesitetag" name="sitetag" type="text" size="60" class="easyui-validatebox" value="" /><font style="color:#999">多个关键字用“,”隔开</font></td>
			</tr>
			<tr>
				<td colspan="2">绑&nbsp;&nbsp;定&nbsp;&nbsp;域&nbsp;&nbsp;名：&nbsp;&nbsp;&nbsp;&nbsp;<input id="updatedomainname" name="domainname" type="text" size="60" class="easyui-validatebox" value="" /><font style="color:#999">如：www.example.com</font></td>
			</tr>
			<tr>
				<td>P&nbsp;C&nbsp;模板密钥：<input id="addmodelname" name="modelname" type="text" class="easyui-validatebox" readonly="readonly" size="34" value="" />
				<input type="hidden" id="addmodelid" name="modelid" value="" /><input type="button" value="选择" onclick="modelcheck('pc')" /></td>
				<td>P&nbsp;C&nbsp;首页：<input id="addindexmodel" name="indexmodel" type="text" class="easyui-validatebox" readonly="readonly" value="" size="18" />
				<input type="button" value="选择" onclick="modelfilecheck('pc')" /></td>
			</tr>
			<tr>
				<td>手机模板密钥：<input id="addphonemodelname" name="phonemodelname" type="text" class="easyui-validatebox" readonly="readonly" size="34" value="" />
				<input type="hidden" id="addphonemodelid" name="phonemodelid" value="" /><input type="button" value="选择" onclick="modelcheck('phone')" /></td>
				<td>手机首页：<input id="addphoneindexmodel" name="phoneindexmodel" type="text" class="easyui-validatebox" readonly="readonly" value="" size="18" />
				<input type="button" value="选择" onclick="modelfilecheck('phone')" /></td>
			</tr>
			<tr>
				<td>平板模板密钥：<input id="addpadmodelname" name="padmodelname" type="text" class="easyui-validatebox" readonly="readonly" size="34" value="" />
				<input type="hidden" id="addpadmodelid" name="padmodelid" value="" /><input type="button" value="选择" onclick="modelcheck('pad')" /></td>
				<td>平板首页：<input id="addpadindexmodel" name="padindexmodel" type="text" class="easyui-validatebox" readonly="readonly" value="" size="18" />
				<input type="button" value="选择" onclick="modelfilecheck('pad')" /></td>
			</tr>
			<tr>
				<td colspan="2" align="center"><a href="javascript:void(0)" class="easyui-linkbutton" id="btn_window_top_update" iconCls="icon-save" plain="true">保存</a></td>
			</tr>
		</table>
	</form>
</div>
<!-- 模版选择 -->
<div id="divmodelborwe" class="easyui-window" title="模板选择" data-options="modal:true,collapsible:false,closed:true,minimizable:false,
	maximizable:false,width:900,height:380">
	<div id="modelborwetools" style="padding:5px;height:auto">
		<a href="javascript:void(0)" id="browe_btn_save" class="easyui-linkbutton" iconCls="icon-save" plain="true">确定选择</a>
	</div>
	<table id="modeldatagrid">
	    <thead>
			<tr>
				<th data-options="field:'id',hidden:true">id</th><!-- hidden -->
				<th data-options="field:'modelname',align:'center',width:30">模板密钥</th>
				<th data-options="field:'modeldesc',align:'center',width:70">模板描述</th>
			</tr>
		</thead>
	</table>
</div>
<!-- 模板文件浏览 -->
<div id="divmodelfileborwe" class="easyui-window" title="模板文件选择" data-options="modal:true,collapsible:false,closed:true,minimizable:false,
	maximizable:false,width:460,height:300">
	<div id="modelfiletools" style="padding:5px;height:auto">
		<a href="javascript:void(0)" id="browe_btn_modelfile" class="easyui-linkbutton" iconCls="icon-save" plain="true">确定选择</a>
	</div>
	<table id="modelfiledatagrid">
	    <thead>
			<tr>
				<th data-options="field:'filename',width:100">文件名</th>
			</tr>
		</thead>
    </table>
</div>
</body>
</html>
<@js.easyui />
<script type="text/javascript">
var modeltype="pc";
var modelfiletype="pc";
jQuery(document).ready(function() {
	//保存按钮事件
	jQuery("#btn_window_top_update").click(function(){
		jQuery("#toupdateform").form({
			url:"${ctx}/sys/site/add",
			onSubmit:function(){
				var servervali = false;
				jQuery.ajax({
		   			async:false,
		   			type:"post",
		   			dataType:"json",
		   			data:{id:jQuery("#updateid").val(),domainname:jQuery("#updatedomainname").val()},
		   			url:"${ctx}/sys/site/validate",
		   			success:function(date){
		   				if(!date.success){
		   					jQuery.messager.alert("信息",date.message,"error");
		   				}else
		   					servervali = true;
		   			}
		   		});
				return servervali;
			},
			success:function(data){
				if(!data){
					jQuery.messager.alert("信息","保存失败！","error");
					return;
				}
				jQuery.messager.alert("信息","保存成功！","info",function(){
					jQuery("#divupdate").window("close");
				});
				jQuery("#datagrid").datagrid("reload");
			}
		});
		//提交表单
		jQuery('#toupdateform').submit();
	});
	//选择模板按钮事件
	jQuery("#browe_btn_save").click(function(){
		var brow = jQuery("#modeldatagrid").datagrid("getSelected");
		if(!brow){
			jQuery.messager.alert("信息","请选择一个模版！","info");
			return;
		}
		if(modeltype=="pad"){
			jQuery("#addpadmodelname").val(brow.modelname);
			jQuery("#addpadmodelid").val(brow.id);
		}else if(modeltype=="phone"){
			jQuery("#addphonemodelname").val(brow.modelname);
			jQuery("#addphonemodelid").val(brow.id);
		}else{
			jQuery("#addmodelname").val(brow.modelname);
			jQuery("#addmodelid").val(brow.id);
		}
		jQuery("#divmodelborwe").window("close");
	});
	//选择模板文件确定按钮
	jQuery("#browe_btn_modelfile").click(function(){
		var brow = jQuery("#modelfiledatagrid").datagrid("getSelected");
		if(!brow){
			jQuery.messager.alert("信息","请选择一个模版！","info");
			return;
		}
		if(modelfiletype=="pad"){
			jQuery("#addpadindexmodel").val(brow.filename);
		}else if(modelfiletype=="phone"){
			jQuery("#addphoneindexmodel").val(brow.filename);
		}else{
			jQuery("#addindexmodel").val(brow.filename);
		}
		jQuery("#divmodelfileborwe").window("close");
	});
});
//显示操作里的内容
function formatterAction(value,row,index){
	return "<img title='配置站点' onclick='editfun(\""+row.id+"\")' src='${ctx}/js/easyui/themes/icons/pencil.png' />&nbsp;&nbsp;"+
	"";
}
//配置站事件
function editfun(id){
	jQuery.ajax({
		async:false,
		type:"post",
		dataType:"json",
		data:{id:id},
		url:"${ctx}/sys/site/bean",
		success:function(date){
			if(!date.success){
				jQuery.messager.alert("信息",date.message,"error");
				return;
			}
			var bean = date.bean;
			jQuery("#divupdate").window("open");
			jQuery("#toupdateform").form("clear");
			
			jQuery("#updateid").val(bean.id);
			jQuery("#updatesitetag").val(bean.sitetag);
			jQuery("#updatedomainname").val(bean.domainname);
			//PC模版信息设置
			jQuery("#addmodelname").val(date.modelname);
			jQuery("#addmodelid").val(bean.modelid);
			jQuery("#addindexmodel").val(bean.indexmodel);
			//phone模版信息设置
			jQuery("#addphonemodelname").val(date.phonemodelname);
			jQuery("#addphonemodelid").val(bean.phonemodelid);
			jQuery("#addphoneindexmodel").val(bean.phoneindexmodel);
			//pad模版信息设置
			jQuery("#addpadmodelname").val(date.padmodelname);
			jQuery("#addpadmodelid").val(bean.padmodelid);
			jQuery("#addpadindexmodel").val(bean.padindexmodel);
		}
	});
}
//模板 选择
function modelcheck(type){
	jQuery("#divmodelborwe").window("open");
	jQuery("#modeldatagrid").datagrid({
		url:"${ctx}/sys/model/search?model="+type,
		singleSelect:true,
		fitColumns:true,
		pagination:true,
		rownumbers:true,
		pageSize:10,
		pageList:[10],
		toolbar:"modelborwetools"
	});
	modeltype=type;
}
//模板文件选择
function modelfilecheck(type){
	jQuery("#divmodelfileborwe").window("open");
	var path="";
	//判断是否已经选择完模板
	if(type=="pad"){
		if(jQuery("#addpadmodelname").val()==""){
			jQuery.messager.alert("信息","请先选择平板的模板再选择平板的首页！","info");
			return;
		}else
			path=jQuery("#addpadmodelname").val();
	}else if(type=="phone"){
		if(jQuery("#addphonemodelname").val()==""){
			jQuery.messager.alert("信息","请先选择手机的模板再选择手机的首页！","info");
			return;
		}else
			path=jQuery("#addphonemodelname").val();
	}else{
		if(jQuery("#addmodelname").val()==""){
			jQuery.messager.alert("信息","请先选择PC的模板再选择PC的首页！","info");
			return;
		}else
			path=jQuery("#addmodelname").val();
	}
	//模板文件读取
	jQuery("#modelfiledatagrid").datagrid({
		url:"${ctx}/sys/model/themes?path="+path,
		singleSelect:true,
		fit:true,
		fitColumns:true,
		rownumbers:true,
		toolbar:"modelfiletools"
	});
	modelfiletype=type;
}
//当配置窗口关闭时的事件
function divupdateclose(){
	jQuery("#divmodelborwe").window("close");
	jQuery("#divmodelfileborwe").window("close");
}
</script>